/*********************************************************************

   CPolyBtn

   Copyright (C) 2003 Smaller Animals Software, Inc.

   This software is provided 'as-is', without any express or implied
   warranty.  In no event will the authors be held liable for any damages
   arising from the use of this software.

   Permission is granted to anyone to use this software for any purpose,
   including commercial applications, and to alter it and redistribute it
   freely, subject to the following restrictions:

   1. The origin of this software must not be misrepresented; you must not
     claim that you wrote the original software. If you use this software
     in a product, an acknowledgment in the product documentation would be
     appreciated but is not required.

   2. Altered source versions must be plainly marked as such, and must not be
     misrepresented as being the original software.

   3. This notice may not be removed or altered from any source distribution.

   http://www.smalleranimals.com
   smallest@smalleranimals.com

**********************************************************************/

#if !defined(AFX_POLYBTN_H__8496BEF2_AB14_4987_8FF2_22317D4B2E5A__INCLUDED_)
#define AFX_POLYBTN_H__8496BEF2_AB14_4987_8FF2_22317D4B2E5A__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
// PolyBtn.h : header file
//
#include "..\stdafx.h"
#include <vector>

#pragma comment(lib, "msimg32.lib") // for TransparentBlt

/////////////////////////////////////////////////////////////////////////////
// CPolyBtn window

class AFX_EXT_CLASS CPolyBtn : public CButton
{
// Construction
public:
	CPolyBtn();

// Operations
public:
   // when using the SetPoints method, you can decide to highlight lines 
   // that are more than -45 degrees below horizontal (default false)
   void AllowHighlightOnGtrNeg45(bool b)  {m_bAllowHighlightOnGtrNeg45=b;}

   // should the button change color when the mouse moves over ? (default false)
   void AllowRollover(bool b)             {m_bAllowRollover = b;}

   // optionally set the colors used.
   void SetColors(COLORREF highlightClr, COLORREF  downclr, COLORREF  focusclr, COLORREF  disabledclr, COLORREF  rolloverclr)
   {
      m_clrHighlight = highlightClr;   // default ::GetSysColor(COLOR_3DHIGHLIGHT)
      m_clrShadow = downclr;           // default ::GetSysColor(COLOR_3DSHADOW);
      m_clrFocus = focusclr;           // default ::GetSysColor(COLOR_3DHIGHLIGHT)
      m_clrDisabled = disabledclr;     // default ::GetSysColor(COLOR_3DSHADOW);
      m_clrRollover = rolloverclr;     // default ::GetSysColor(COLOR_3DHIGHLIGHT);
   }

   // set the color to fill with. default ::GetSysColor(COLOR_BTNFACE);
   void SetFillColor(COLORREF fillClr)    {m_clrFill = fillClr;}

   // give it a vector of points and it will figure out the colors by itself.
   // points must be in clockwise order for the automatic lightsource coloring to work correctly.
   // if the points are in clockwise order, the highlights will appear to come from the bottom-right
   // instead of the typical top-left.
   void SetPoints(std::vector<CPoint> &points);

   // or, supply all the edges, colored individually. 
   struct CEdge
   {
      CPoint start, end;
      COLORREF  clr;
      COLORREF  downclr;
      COLORREF  focusclr;
      COLORREF  disabledclr;
      COLORREF  rolloverclr;
   };
   // this method offers more flexible coloring, but is a little more tedious to use
   void SetEdges(std::vector<CEdge> &edges);
   
   // set a bitmap to be drawn
   void SetBMPID(UINT id, COLORREF clrTrans, UINT disabledBitmapID=0, COLORREF clrTransDisabled=0)    
   {
      m_bmpID = id; 
      m_clrTrans = clrTrans;
      m_bmpIDD = disabledBitmapID;
      m_clrTransD = clrTransDisabled;
   }    

   // draw bitmap at this offset
   void SetBMPOffset(int x, int y)  {m_bmpOffset = CPoint(x,y);}

   // draw window text at this offset
   void SetTextOffset(int x, int y) {m_textOffset = CPoint(x,y);}

   // optional tooltip
	void SetTooltipText(LPCTSTR lpszText, BOOL bActivate = TRUE);
	void ActivateTooltip(BOOL bEnable = TRUE);

// Overrides
	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CPolyBtn)
	public:
	virtual void DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct);
	virtual BOOL PreTranslateMessage(MSG* pMsg);
	protected:
	virtual void PreSubclassWindow();
	//}}AFX_VIRTUAL

// Implementation
public:
	virtual ~CPolyBtn();

	// Generated message map functions
protected:
	//{{AFX_MSG(CPolyBtn)
	afx_msg BOOL OnEraseBkgnd(CDC* pDC);
	afx_msg void OnMouseMove(UINT nFlags, CPoint point);
	//}}AFX_MSG
   afx_msg LRESULT OnMouseLeave(WPARAM wParam, LPARAM lParam);
	DECLARE_MESSAGE_MAP()

   void _TransparentBlt(CDC &dc, CBitmap &bmp, int xpos, int ypos, COLORREF clrTrans);

   void         InitToolTip();
   CToolTipCtrl m_ToolTip;

   ////////////////

   std::vector<CEdge> m_edges;
   POINT    * m_pPoints;

   CRgn     m_rgn;
   CRgn     m_rgnWnd;

   CBitmap  m_bmp;
   CBitmap  m_bmpD;
   UINT     m_bmpID;
   UINT     m_bmpIDD;
   COLORREF m_clrTrans;
   COLORREF m_clrTransD;

   CPoint   m_bmpOffset; 
   CPoint   m_textOffset;

   bool     m_bAllowRollover;

   COLORREF m_clrHighlight, m_clrShadow, m_clrRollover, m_clrFocus, m_clrDisabled, m_clrFill;

   bool m_bAllowHighlightOnGtrNeg45;
   bool m_bMouseOnButton;
};

/////////////////////////////////////////////////////////////////////////////

//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.

#endif // !defined(AFX_POLYBTN_H__8496BEF2_AB14_4987_8FF2_22317D4B2E5A__INCLUDED_)
